package com.example.helloword.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Locale;

/**
 * @create 2022-03-2022/3/9-17:17
 */
//拓展SpringMVC
//自己的配置
@Configuration
public class Myconfig implements WebMvcConfigurer {

    //起始页配置
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("test/index");
        registry.addViewController("/index").setViewName("test/index");
        registry.addViewController("").setViewName("test/index");

        registry.addViewController("/show.html").setViewName("dashboard");
    }
    //
    @Bean
    public LocaleResolver localeResolver(){
        return  new MyLocaleResolver();
    }


    //添加自己的拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //add添加 exclude排除
        registry.addInterceptor(new LoginHandleIntercepter()).addPathPatterns("/**").excludePathPatterns("/","/index","","/show","/asserts/**","/hello");
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
